#!/bin/bash

set -eu

export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH"
ARCH="$($SNAP/bin/uname -m)"
export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu"

if [ ! -f "${SNAP_DATA}/bin/cilium" ]; then
  echo "Cilium not available, try enabling it with 'microk8s enable cilium'" >&2
  exit 0
fi

source $SNAP/actions/common/utils.sh
exit_if_stopped
export CILIUM_MONITOR_SOCK="$SNAP_DATA/var/run/cilium/monitor1_2.sock"
export CILIUM_HEALTH_SOCK="$SNAP_DATA/var/run/cilium/health.sock"
"${SNAP_DATA}/bin/cilium" -H "unix:///var/snap/microk8s/current/var/run/cilium/cilium.sock" "$@"
